/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
// TODO 芋艿：【锁屏】可能后面删除掉
import dayjs from 'dayjs'

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const DATE_FORMAT = 'YYYY-MM-DD'

export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format)
}

export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
  return dayjs(date).format(format)
}

export function curDayStart() {
  return dayjs().startOf('date').format(DATE_TIME_FORMAT)
}

export function curDayEnd() {
  return dayjs().endOf('date').format(DATE_TIME_FORMAT)
}

export function formatTimestamp(_date: Date) {
  return dayjs(_date).format("YYYY-MM-DD")
}

export function calculateAge( _birthDay: Date) {
  const birthday = dayjs(_birthDay);
  const today = dayjs(new Date());
  return today.diff(birthday, 'year');
}

export function calculateHours( start: Date, end: Date) {
  return  dayjs(end).diff(dayjs(start), 'hour');
}

export function isCurrentDay( _date: Date) {
  const today = dayjs(new Date());
  return today.isSame( dayjs(_date), 'day' )
}

export const dateUtil = dayjs
